package com.dgshanger.sanhxiaofeisc.mvp.presenter

import com.dgshanger.sanhxiaofeisc.entity.NearbyItemEntity
import com.dgshanger.sanhxiaofeisc.entity.SearchHotEntity
import com.dgshanger.sanhxiaofeisc.mvp.contract.SearchContract
import com.dgshanger.sanhxiaofeisc.mvp.model.SearchModel
import com.xx.baseuilibrary.mvp.BaseMvpPresenter
import com.xx.baseutilslibrary.network.rx.XxBaseHttpObserver

/**
 * Created by JacobHHH on 2018/5/4.
 */
class SearchPresenter : BaseMvpPresenter<SearchContract.Model,SearchContract.View>(),  SearchContract.Presenter{

    override fun loadHotData() {
       getModel().loadHotData(object : XxBaseHttpObserver<List<SearchHotEntity>>(){

           override fun onCompleted(msg: String?, entity: List<SearchHotEntity>?) {
               getView()?.setHotData(entity)
           }

           override fun onError(error: String?) {
              getView()?.showToast(error)
           }

           override fun onStart() {

           }

           override fun onFinish() {

           }

       })
    }

    override fun search(location_name: String?, user_longitude: String?, user_latitude: String?,
                        shop_name: String?) {
        getModel().search(location_name,user_longitude,user_latitude,shop_name
                , object : XxBaseHttpObserver<List<NearbyItemEntity>>(){
            override fun onCompleted(msg: String?, entity: List<NearbyItemEntity>?) {
                getView()?.setSearchResult(entity)
            }

            override fun onError(error: String?) {
                getView()?.showToast(error)
            }

            override fun onStart() {
               getView()?.showLoadingDialog("正在搜索...")
            }

            override fun onFinish() {
                getView()?.dismissLoadingDialog()
            }

        })
    }

    override fun createModel(): SearchContract.Model =SearchModel()
}